home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / bserverdir / sources / clients / line.c < prev    next >
C/C++ Source or Header  |  1994-11-28  |  4KB  |  192 lines

  1. ;/*
  2. sc Line.c DATA=FAR NMINC STRMERGE NOSTKCHK IGNORE=73 STRUCTUREEQUIVALENCE NOSTDIO
  3. slink from LIB:c.o Line.o to //Clients/Line LIB LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD NOICONS STRIPDEBUG
  4. delete Line.o
  5. quit
  6.  
  7.  Line 1.2  (Client for BServer)
  8.  
  9.  Copyright © 1994 by Stefano Reksten of 3AM - The Three Amigos!!!
  10.  All rights reserved.
  11. */
  12.  
  13. #include <exec/types.h>
  14. #include <intuition/intuition.h>
  15.  
  16. #include <clib/exec_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/graphics_protos.h>
  19. #include <clib/alib_protos.h>
  20. #include <stdlib.h>
  21. #include <time.h>
  22.  
  23. #include "/include/client.h"
  24.  
  25. struct IntuitionBase *IntuitionBase;
  26. struct GfxBase *GfxBase;
  27.  
  28. struct DisplayIDInformation *dinfo;
  29.  
  30. #define LINENUM 40
  31. #define LASTLINE 39
  32.  
  33. struct { WORD FromX, FromY, ToX, ToY; } Line[LINENUM];
  34. WORD IncX, IncY, IncTX, IncTY;
  35.  
  36. extern ULONG RangeSeed;
  37.  
  38. void DrawLine( void )
  39. {
  40. UWORD n, swidth, sheight;
  41. struct Rectangle *rect;
  42. register ULONG total_Line = 0;
  43. UBYTE r, g, b;
  44. struct Screen *scr;
  45.  
  46. rect = GETTXTOSCANRECT(dinfo);
  47.  
  48. swidth = RECTANGLEWIDTH(rect);
  49. sheight = RECTANGLEHEIGHT(rect);
  50.  
  51. if ( scr = OpenScreenTags( NULL,
  52.     SA_DisplayID, DISPLAYID( dinfo ),
  53.     SA_Width, swidth,
  54.     SA_Height, sheight,
  55.     SA_Left, (RECTANGLEWIDTH(rect) - swidth)/2,
  56.     SA_Top, 0,
  57.     SA_Depth, 1,
  58.     SA_Overscan, OSCAN_TEXT,
  59.     SA_Type, CUSTOMSCREEN,
  60.     SA_Quiet, TRUE,
  61.     TAG_END ) )
  62.     {
  63.     register struct ViewPort *vp = &(scr->ViewPort);
  64.     register struct RastPort *rp = &(scr->RastPort);
  65.  
  66.     SpritesOff();
  67.  
  68.     r = 6; g = 7; b = 9;
  69.     SetRGB4( vp, 0, 0, 0, 0 );
  70.     SetRGB4( vp, 1, r, g, b );
  71.     SetAPen( rp, 1 );
  72.     SetDrMd( rp, COMPLEMENT );
  73.  
  74.     Line[0].FromX = RangeRand( swidth );
  75.     Line[0].FromY = RangeRand( sheight );
  76.     Line[0].ToX = RangeRand( swidth - Line[0].FromX + 4);
  77.     Line[0].ToY = RangeRand( sheight - Line[0].FromY + 4);
  78.  
  79.     IncX = RangeRand( 40 ) - 19;
  80.     IncY = RangeRand( 40 ) - 19;
  81.     IncTX = RangeRand( 40 ) - 19;
  82.     IncTY = RangeRand( 40 ) - 19;
  83.  
  84.     while( STILL_BLANKING )
  85.         {
  86.         WaitTOF();
  87.  
  88.         if ( total_Line++ > LASTLINE )
  89.             {
  90.             Move( rp, Line[LASTLINE].FromX, Line[LASTLINE].FromY );
  91.             Draw( rp, Line[LASTLINE].ToX, Line[LASTLINE].ToY );
  92.             }
  93.  
  94.         for ( n = LASTLINE; n; n-- )
  95.             {
  96.             Line[n].FromX = Line[n-1].FromX;
  97.             Line[n].FromY = Line[n-1].FromY;
  98.             Line[n].ToX = Line[n-1].ToX;
  99.             Line[n].ToY = Line[n-1].ToY;
  100.             }
  101.  
  102.         if ( Line[0].FromX + IncX <= 0 )
  103.             {
  104.             Line[0].FromX = 0;
  105.             IncX = RangeRand( 20 ) + 1;
  106.             }
  107.         else
  108.         if ( Line[0].FromX + IncX >= swidth )
  109.             {
  110.             Line[0].FromX = swidth - 1;
  111.             IncX = RangeRand( 20 ) * (-1) - 1;
  112.             }
  113.         else
  114.             Line[0].FromX += IncX;
  115.  
  116.         if ( Line[0].FromY + IncY < 0 )
  117.             {
  118.             Line[0].FromY = 0;
  119.             IncY = RangeRand( 20 ) + 1;
  120.             }
  121.         else
  122.         if ( Line[0].FromY + IncY >= sheight )
  123.             {
  124.             Line[0].FromY = sheight - 1;
  125.             IncY = RangeRand( 20 ) * (-1) - 1;
  126.             }
  127.         else
  128.             Line[0].FromY += IncY;
  129.  
  130.         if ( Line[0].ToX + IncTX <= 0 )
  131.             {
  132.             Line[0].ToX = 0;
  133.             IncTX = RangeRand( 20 ) + 1;
  134.             }
  135.         else
  136.         if ( Line[0].ToX + IncTX >= swidth )
  137.             {
  138.             Line[0].ToX = swidth - 1;
  139.             IncTX = RangeRand( 20 ) * (-1) - 1;
  140.             }
  141.         else
  142.             Line[0].ToX += IncTX;
  143.  
  144.         if ( Line[0].ToY + IncTY < 0 )
  145.             {
  146.             Line[0].ToY = 0;
  147.             IncTY = RangeRand( 20 ) + 1;
  148.             }
  149.         else
  150.         if ( Line[0].ToY + IncTY >= sheight )
  151.             {
  152.             Line[0].ToY = sheight - 1;
  153.             IncTY = RangeRand( 20 ) * (-1) - 1;
  154.             }
  155.         else
  156.             Line[0].ToY += IncTY;
  157.  
  158.         Move( rp, Line[0].FromX, Line[0].FromY );
  159.         Draw( rp, Line[0].ToX, Line[0].ToY );
  160.  
  161.         r += RangeRand( 3 ) - 1; if ( r < 0 ) r = 0; if ( r > 15 ) r = 15;
  162.         g += RangeRand( 3 ) - 1; if ( g < 0 ) g = 0; if ( g > 15 ) g = 15;
  163.         b += RangeRand( 3 ) - 1; if ( b < 0 ) b = 0; if ( b > 15 ) b = 15;
  164.         SetRGB4( vp, 1, r, g, b );
  165.         }
  166.  
  167.     CloseScreen( scr );
  168.     SpritesOn();
  169.     }
  170. else
  171.     SendClientMsg( ACTION_FAILED );
  172. }
  173.  
  174.  
  175. void __main( char *line )
  176. {
  177. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 37L ) )
  178.     {
  179.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 37L ) )
  180.         {
  181.         if ( dinfo = OpenCommunication() )
  182.             {
  183.             RangeSeed = time( NULL );
  184.             DrawLine();
  185.             CloseCommunication( dinfo );
  186.             }
  187.         CloseLibrary( (struct Library *)GfxBase );
  188.         }
  189.     CloseLibrary( (struct Library *)IntuitionBase );
  190.     }
  191. }
  192.